<!DOCTYPE html><html><head>
      <title>策略对象</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
      <link rel="stylesheet" href="../yangshi.css">
      
      
      
      
      
      <style>
      code[class*=language-],pre[class*=language-]{color:#333;background:0 0;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.4;-moz-tab-size:8;-o-tab-size:8;tab-size:8;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:.8em;overflow:auto;border-radius:3px;background:#f5f5f5}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal;background:#f5f5f5}.token.blockquote,.token.comment{color:#969896}.token.cdata{color:#183691}.token.doctype,.token.macro.property,.token.punctuation,.token.variable{color:#333}.token.builtin,.token.important,.token.keyword,.token.operator,.token.rule{color:#a71d5d}.token.attr-value,.token.regex,.token.string,.token.url{color:#183691}.token.atrule,.token.boolean,.token.code,.token.command,.token.constant,.token.entity,.token.number,.token.property,.token.symbol{color:#0086b3}.token.prolog,.token.selector,.token.tag{color:#63a35c}.token.attr-name,.token.class,.token.class-name,.token.function,.token.id,.token.namespace,.token.pseudo-class,.token.pseudo-element,.token.url-reference .token.variable{color:#795da3}.token.entity{cursor:help}.token.title,.token.title .token.punctuation{font-weight:700;color:#1d3e81}.token.list{color:#ed6a43}.token.inserted{background-color:#eaffea;color:#55a532}.token.deleted{background-color:#ffecec;color:#bd2c00}.token.bold{font-weight:700}.token.italic{font-style:italic}.language-json .token.property{color:#183691}.language-markup .token.tag .token.punctuation{color:#333}.language-css .token.function,code.language-css{color:#0086b3}.language-yaml .token.atrule{color:#63a35c}code.language-yaml{color:#183691}.language-ruby .token.function{color:#333}.language-markdown .token.url{color:#795da3}.language-makefile .token.symbol{color:#795da3}.language-makefile .token.variable{color:#183691}.language-makefile .token.builtin{color:#0086b3}.language-bash .token.keyword{color:#0086b3}pre[data-line]{position:relative;padding:1em 0 1em 3em}pre[data-line] .line-highlight-wrapper{position:absolute;top:0;left:0;background-color:transparent;display:block;width:100%}pre[data-line] .line-highlight{position:absolute;left:0;right:0;padding:inherit 0;margin-top:1em;background:hsla(24,20%,50%,.08);background:linear-gradient(to right,hsla(24,20%,50%,.1) 70%,hsla(24,20%,50%,0));pointer-events:none;line-height:inherit;white-space:pre}pre[data-line] .line-highlight:before,pre[data-line] .line-highlight[data-end]:after{content:attr(data-start);position:absolute;top:.4em;left:.6em;min-width:1em;padding:0 .5em;background-color:hsla(24,20%,50%,.4);color:#f4f1ef;font:bold 65%/1.5 sans-serif;text-align:center;vertical-align:.3em;border-radius:999px;text-shadow:none;box-shadow:0 1px #fff}pre[data-line] .line-highlight[data-end]:after{content:attr(data-end);top:auto;bottom:.4em}html body{font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ol,html body>ul{margin-bottom:16px}html body ol,html body ul{padding-left:2em}html body ol.no-list,html body ul.no-list{padding:0;list-style-type:none}html body ol ol,html body ol ul,html body ul ol,html body ul ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;background-color:#f0f0f0;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:700;color:#000}html body table td,html body table th{border:1px solid #d6d6d6;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:700}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em;color:#000;background-color:#f0f0f0;border-radius:3px;padding:.2em 0}html body code::after,html body code::before{letter-spacing:-.2em;content:'\00a0'}html body pre>code{padding:0;margin:0;word-break:normal;white-space:pre;background:0 0;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;line-height:1.45;border:#d6d6d6;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:after,html body pre code:before,html body pre tt:after,html body pre tt:before{content:normal}html body blockquote,html body dl,html body ol,html body p,html body pre,html body ul{margin-top:0;margin-bottom:16px}html body kbd{color:#000;border:1px solid #d6d6d6;border-bottom:2px solid #c7c7c7;padding:2px 4px;background-color:#f0f0f0;border-radius:3px}@media print{html body{background-color:#fff}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#000;page-break-after:avoid}html body blockquote{color:#5c5c5c}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body code,html body pre{word-wrap:break-word;white-space:pre}}.markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview ul{list-style:disc}.markdown-preview ul ul{list-style:circle}.markdown-preview ul ul ul{list-style:square}.markdown-preview ol{list-style:decimal}.markdown-preview ol ol,.markdown-preview ul ol{list-style-type:lower-roman}.markdown-preview ol ol ol,.markdown-preview ol ul ol,.markdown-preview ul ol ol,.markdown-preview ul ul ol{list-style-type:lower-alpha}.markdown-preview .newpage,.markdown-preview .pagebreak{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center!important}.markdown-preview:not([data-for=preview]) .code-chunk .code-chunk-btn-group{display:none}.markdown-preview:not([data-for=preview]) .code-chunk .status{display:none}.markdown-preview:not([data-for=preview]) .code-chunk .output-div{margin-bottom:16px}.markdown-preview .md-toc{padding:0}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link div,.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link p{display:inline}.markdown-preview .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,.66);border:4px solid rgba(150,150,150,.66);background-clip:content-box}html body[for=html-export]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0;min-height:100vh}@media screen and (min-width:914px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px + 2em)}}@media screen and (max-width:914px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{font-size:14px!important;padding:1em}}@media print{html body[for=html-export]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for=html-export]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,.66);border:4px solid rgba(150,150,150,.66);background-clip:content-box}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc{padding:0 16px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link div,html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link p{display:inline}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% - 300px);padding:2em calc(50% - 457px - 300px / 2);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for=html-export]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for=html-export]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}
/* Please visit the URL below for more information: */
/*   https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */

      </style>
      <!-- The content below will be included at the end of the <head> element. --><script type="text/javascript">
  document.addEventListener("DOMContentLoaded", function () {
    // your code here
  });
</script></head><body for="html-export">
    
    
      <div class="crossnote markdown-preview  ">
      
<p><span style="font-size: 32px; font-weight: bold;">目录</span></p>
<div class="code-chunk" data-id="code-chunk-id-0" data-cmd="toc"><div class="input-div"><div class="code-chunk-btn-group"><div class="run-btn btn btn-xs btn-primary"><span>▶︎</span></div><div class="run-all-btn btn btn-xs btn-primary">all</div></div><div class="status">running...</div></div><div class="output-div"></div></div><ul>
<li><a href="#1-%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1%E5%B1%9E%E6%80%A7">1、策略对象属性</a>
<ul>
<li><a href="#11-%E7%AD%96%E7%95%A5%E7%BC%96%E5%8F%B7">1.1、策略编号</a></li>
<li><a href="#12-%E7%AD%96%E7%95%A5%E5%90%8D">1.2、策略名</a></li>
<li><a href="#13-%E8%B4%A6%E6%88%B7%E5%88%97%E8%A1%A8">1.3、账户列表</a></li>
<li><a href="#14-%E4%BA%A4%E6%98%93%E8%AE%BE%E7%BD%AE%E5%AD%97%E6%AE%B5">1.4、交易设置字段</a></li>
<li><a href="#15-%E4%BA%A4%E6%98%93%E5%90%AF%E5%8A%A8">1.5、交易启动</a></li>
<li><a href="#16-k%E7%BA%BF%E6%95%B0%E6%8D%AE">1.6、k线数据</a></li>
<li><a href="#17-tick%E6%95%B0%E6%8D%AE">1.7、tick数据</a></li>
<li><a href="#18-%E5%89%8D%E4%B8%80%E5%91%A8%E6%9C%9F%E6%97%B6%E9%97%B4">1.8、前一周期时间</a></li>
<li><a href="#19-%E4%B8%8A%E6%AC%A1%E5%BC%80%E4%BB%93%E7%BC%96%E5%8F%B7">1.9、上次开仓编号</a></li>
<li><a href="#110-%E7%90%86%E8%AE%BA%E5%BC%80%E5%B9%B3%E4%BB%93%E6%97%B6%E9%97%B4-%E6%95%B0%E9%87%8F-%E7%8A%B6%E6%80%81-%E4%BB%B7%E6%A0%BC%E5%92%8C%E7%BC%96%E5%8F%B7">1.10、理论开平仓时间、数量、状态、价格和编号</a></li>
<li><a href="#111-%E5%8E%86%E5%8F%B2%E4%BA%A4%E6%98%93%E8%AE%B0%E5%BD%95">1.11、历史交易记录</a></li>
<li><a href="#112-%E6%8C%81%E4%B9%85%E5%8C%96%E6%95%B0%E6%8D%AE%E8%A1%A8">1.12、持久化数据表</a></li>
<li><a href="#113-%E8%BE%93%E5%87%BA%E6%8C%87%E6%A0%87%E5%BA%8F%E5%88%97%E6%AF%8F%E6%A0%B9k%E7%BA%BF%E4%BF%9D%E5%AD%98%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%BE%93%E5%87%BA%E6%98%BE%E7%A4%BA%E7%9A%84%E5%9B%9B%E4%B8%AA%E6%8C%87%E6%A0%87">1.13、输出指标序列每根k线保存（也就是输出显示的四个指标）</a></li>
<li><a href="#114-%E4%B9%98%E5%80%BC%E5%92%8C%E6%9C%80%E5%B0%8F%E5%8F%98%E5%8A%A8%E5%8D%95%E4%BD%8D">1.14、乘值和最小变动单位</a></li>
<li><a href="#115-%E4%B8%8A%E6%AC%A1%E5%BC%80%E4%BB%93%E6%88%96%E5%B9%B3%E4%BB%93%E5%88%B0%E5%BD%93%E5%89%8Dk%E7%BA%BF%E6%95%B0%E9%87%8F%E8%B7%9D%E7%A6%BB">1.15、上次开仓或平仓到当前k线数量（距离）</a></li>
<li><a href="#116-%E5%BD%93%E5%89%8Dk%E7%BA%BF%E6%98%AF%E5%90%A6%E6%9C%89%E4%BA%A4%E6%98%93%E4%BF%A1%E5%8F%B7">1.16、当前k线是否有交易信号</a></li>
<li><a href="#117-%E5%BD%93%E5%89%8Dk%E7%BA%BF%E6%98%AF%E5%90%A6%E6%9B%B4%E6%96%B0">1.17、当前k线是否更新</a></li>
</ul>
</li>
<li><a href="#2-%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95">2、策略对象方法</a>
<ul>
<li><a href="#21-%E8%8E%B7%E5%8F%96n%E6%A0%B9k%E7%BA%BF%E5%89%8D%E7%9A%84%E6%97%A5%E6%9C%9F">2.1、获取n根k线前的日期</a></li>
<li><a href="#21-%E8%8E%B7%E5%8F%96n%E6%A0%B9k%E7%BA%BF%E5%89%8D%E7%9A%84%E6%97%B6%E9%97%B4">2.1、获取n根k线前的时间</a></li>
</ul>
</li>
</ul>
<hr>
<p><a href="https://www.bilibili.com/video/BV13w411A7rL/" target="_blank" style="font-size:16px;">视频教程</a></p>
<hr>
<h4 id="1-策略对象属性">1、策略对象属性 </h4>
<h5 id="11-策略编号">1.1、策略编号 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>bianhao <span class="token comment"># 策略编号，和工作区中的编号对应，例如： 0,1,2,3</span>
cl<span class="token punctuation">.</span>thread_name  <span class="token comment">#  策略编号，和工作区中的编号对应，例如： 0,1,2,3</span>
</code></pre><p><img src="../img/%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1/%E7%AD%96%E7%95%A5%E7%BC%96%E5%8F%B7.png" alt="在这里插入图片描述"></p>
<hr>
<h5 id="12-策略名">1.2、策略名 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>name  <span class="token comment">#  策略名，此策略对象的唯一标识，由软件名+编号+策略名+合约+周期组成，例如：ruanjian8.0_单均线策略预警_v1_KQ.m@SHFE.rb_60s</span>
</code></pre><h5 id="13-账户列表">1.3、账户列表 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>zhanghu  <span class="token comment">#  账户对象列表，第一个为编号0的账户，后面一次类推。例如：[账户对象0，账户对象1],账户列表的顺序与账户配置的顺序一样</span>
</code></pre><p><img src="../img/%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1/%E8%B4%A6%E6%88%B7%E9%85%8D%E7%BD%AE.png" alt="在这里插入图片描述"></p>
<p><a href="%E8%B4%A6%E6%88%B7%E5%AF%B9%E8%B1%A1.html">策略对象的属性和方法详见《账户对象》</a></p>
<hr>
<h5 id="14-交易设置字段">1.4、交易设置字段 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>jiaoyishezhi <span class="token comment">#  交易设置，详见功能字段设置说明，其中包含了用户设置的所有参数，参数可以通过软件设置动态调整。</span>
<span class="token comment"># [[0], [1, 1, 1], [1, 36, 1, 88], ['ag2310'], ['IH', 'IC', 'IF', 'IM'], [2, 30, '螺纹', 'ruanjian8.'], 'ruanjian8.0_单均线策略预警_v1_KQ.m@SHFE.rb_60s', 1, [0, 0, 1, 1], [0]]</span>
</code></pre><p><a href="../%E5%8A%9F%E8%83%BD%E5%AD%97%E6%AE%B5%E8%AE%BE%E7%BD%AE%E8%AF%B4%E6%98%8E.html">交易设置字段说明详见《功能字段设置说明》</a></p>
<hr>
<h5 id="15-交易启动">1.5、交易启动 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code><span class="token comment"># 一般用于tick高频策略，调用账户对象直接下单，加到策略逻辑前面，图表策略中不要使用，用了回测不了。</span>
cl<span class="token punctuation">.</span>jiaoyiqidong <span class="token comment">#  是否启动了实盘交易，软件中启动了交易这里为True，否则为False</span>
</code></pre><p><img src="../img/%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1/%E5%90%AF%E5%8A%A8%E4%BA%A4%E6%98%93.png" alt="在这里插入图片描述"></p>
<hr>
<h5 id="16-k线数据">1.6、k线数据 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>klines <span class="token comment">#  k线数据列表，为df，根据设置中的数据合约顺序存放</span>
</code></pre><p>1.6.1、数据合约设置<br>
<img src="../img/%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1/%E6%95%B0%E6%8D%AE%E5%90%88%E7%BA%A6.png" alt="在这里插入图片描述"></p>
<p>1.6.2、实盘时数据表结构，其他功能第二位设置为0或2.</p>
<table>
<thead>
<tr>
<th style="text-align:left"></th>
<th style="text-align:left">datetime</th>
<th style="text-align:left">id</th>
<th style="text-align:left">open</th>
<th style="text-align:left">high</th>
<th style="text-align:left">low</th>
<th style="text-align:left">close</th>
<th style="text-align:left">volume</th>
<th style="text-align:left">open_oi</th>
<th style="text-align:left">close_oi</th>
<th style="text-align:left">symbol</th>
<th style="text-align:left">duration</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">0</td>
<td style="text-align:left">1.58E+18</td>
<td style="text-align:left">34632</td>
<td style="text-align:left">5749</td>
<td style="text-align:left">5757.2</td>
<td style="text-align:left">5743</td>
<td style="text-align:left">5748.4</td>
<td style="text-align:left">558</td>
<td style="text-align:left">113022</td>
<td style="text-align:left">113066</td>
<td style="text-align:left">CFFEX.IC2308</td>
<td style="text-align:left">60</td>
</tr>
<tr>
<td style="text-align:left">1</td>
<td style="text-align:left">1.58E+18</td>
<td style="text-align:left">34633</td>
<td style="text-align:left">5748.4</td>
<td style="text-align:left">5754.8</td>
<td style="text-align:left">5739</td>
<td style="text-align:left">5746</td>
<td style="text-align:left">573</td>
<td style="text-align:left">113066</td>
<td style="text-align:left">113202</td>
<td style="text-align:left">CFFEX.IC2308</td>
<td style="text-align:left">60</td>
</tr>
<tr>
<td style="text-align:left">2</td>
<td style="text-align:left">1.58E+18</td>
<td style="text-align:left">34634</td>
<td style="text-align:left">5746</td>
<td style="text-align:left">5763.6</td>
<td style="text-align:left">5743.2</td>
<td style="text-align:left">5762.6</td>
<td style="text-align:left">845</td>
<td style="text-align:left">113202</td>
<td style="text-align:left">113189</td>
<td style="text-align:left">CFFEX.IC2308</td>
<td style="text-align:left">60</td>
</tr>
<tr>
<td style="text-align:left">3</td>
<td style="text-align:left">1.58E+18</td>
<td style="text-align:left">34635</td>
<td style="text-align:left">5762.6</td>
<td style="text-align:left">5767</td>
<td style="text-align:left">5740</td>
<td style="text-align:left">5742</td>
<td style="text-align:left">677</td>
<td style="text-align:left">113189</td>
<td style="text-align:left">113137</td>
<td style="text-align:left">CFFEX.IC2308</td>
<td style="text-align:left">60</td>
</tr>
</tbody>
</table>
<p>1.6.3、回测模式时数据表结构，其他功能第二位设置为5/6/7/8/9时。</p>
<table>
<thead>
<tr>
<th style="text-align:left"></th>
<th style="text-align:left">datetime2</th>
<th style="text-align:left">date</th>
<th style="text-align:left">time</th>
<th style="text-align:left">heyue</th>
<th style="text-align:left">open</th>
<th style="text-align:left">high</th>
<th style="text-align:left">low</th>
<th style="text-align:left">close</th>
<th style="text-align:left">volume</th>
<th style="text-align:left">openInterest</th>
<th style="text-align:left">fqxs</th>
<th style="text-align:left">datetime</th>
<th style="text-align:left">tradeDate</th>
<th style="text-align:left">o_date</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">0</td>
<td style="text-align:left">2022/1/4 9:00</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">0.09</td>
<td style="text-align:left">rb2205</td>
<td style="text-align:left">4302</td>
<td style="text-align:left">4354</td>
<td style="text-align:left">4302</td>
<td style="text-align:left">4317</td>
<td style="text-align:left">212385</td>
<td style="text-align:left">1855857</td>
<td style="text-align:left">1.153711</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">2022/1/4</td>
</tr>
<tr>
<td style="text-align:left">1</td>
<td style="text-align:left">2022/1/4 9:15</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">0.0915</td>
<td style="text-align:left">rb2205</td>
<td style="text-align:left">4317</td>
<td style="text-align:left">4327</td>
<td style="text-align:left">4291</td>
<td style="text-align:left">4318</td>
<td style="text-align:left">124204</td>
<td style="text-align:left">1851738</td>
<td style="text-align:left">1.153711</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">2022/1/4</td>
</tr>
<tr>
<td style="text-align:left">2</td>
<td style="text-align:left">2022/1/4 9:30</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">0.093</td>
<td style="text-align:left">rb2205</td>
<td style="text-align:left">4318</td>
<td style="text-align:left">4348</td>
<td style="text-align:left">4315</td>
<td style="text-align:left">4346</td>
<td style="text-align:left">126852</td>
<td style="text-align:left">1860569</td>
<td style="text-align:left">1.153711</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">2022/1/4</td>
</tr>
<tr>
<td style="text-align:left">3</td>
<td style="text-align:left">2022/1/4 9:45</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">0.0945</td>
<td style="text-align:left">rb2205</td>
<td style="text-align:left">4346</td>
<td style="text-align:left">4380</td>
<td style="text-align:left">4341</td>
<td style="text-align:left">4380</td>
<td style="text-align:left">141551</td>
<td style="text-align:left">1873577</td>
<td style="text-align:left">1.153711</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">20220104</td>
<td style="text-align:left">2022/1/4</td>
</tr>
</tbody>
</table>
<p>1.6.4、实盘模式时，最后一行为最新的一根k线数据，这根K线是实时更新的，如果功能设置为每tick运行一次，最后一行会0.5秒更新一次，直到收盘后生成最终k线，然后再更新下一根。</p>
<hr>
<h5 id="17-tick数据">1.7、tick数据 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>tick  <span class="token comment"># tick数据，由tick驱动更新，轮询驱动时为空字典</span>

<span class="token punctuation">{</span><span class="token string">'DateTime'</span><span class="token punctuation">:</span> <span class="token string">'20230915113000'</span><span class="token punctuation">,</span> <span class="token string">'TradingDay'</span><span class="token punctuation">:</span> <span class="token number">20230915</span><span class="token punctuation">,</span> <span class="token string">'Symbol'</span><span class="token punctuation">:</span> <span class="token string">'IF2310.'</span><span class="token punctuation">,</span> <span class="token string">'InstrumentID'</span><span class="token punctuation">:</span> <span class="token string">'IF2310'</span><span class="token punctuation">,</span> <span class="token string">'LastPrice'</span><span class="token punctuation">:</span> <span class="token number">3742.0</span><span class="token punctuation">,</span> 
<span class="token string">'Volume'</span><span class="token punctuation">:</span> <span class="token number">41918.0</span><span class="token punctuation">,</span> <span class="token string">'Turnover'</span><span class="token punctuation">:</span> <span class="token number">47074422480.0</span><span class="token punctuation">,</span> <span class="token string">'OpenInterest'</span><span class="token punctuation">:</span> <span class="token number">89617.0</span><span class="token punctuation">,</span> <span class="token string">'AveragePrice'</span><span class="token punctuation">:</span> <span class="token number">1123012.1303497304</span><span class="token punctuation">,</span> <span class="token string">'OpenPrice'</span><span class="token punctuation">:</span> <span class="token number">3748.8</span><span class="token punctuation">,</span> 
<span class="token string">'HighestPrice'</span><span class="token punctuation">:</span> <span class="token number">3757.0</span><span class="token punctuation">,</span> <span class="token string">'LowestPrice'</span><span class="token punctuation">:</span> <span class="token number">3726.2</span><span class="token punctuation">,</span> <span class="token string">'ClosePrice'</span><span class="token punctuation">:</span> <span class="token number">0.0</span><span class="token punctuation">,</span> <span class="token string">'SettlementPrice'</span><span class="token punctuation">:</span> <span class="token number">0.0</span><span class="token punctuation">,</span> <span class="token string">'UpperLimitPrice'</span><span class="token punctuation">:</span> <span class="token number">4107.6</span><span class="token punctuation">,</span> 
<span class="token string">'LowerLimitPrice'</span><span class="token punctuation">:</span> <span class="token string">'3360.8'</span><span class="token punctuation">,</span> <span class="token string">'PreClosePrice'</span><span class="token punctuation">:</span> <span class="token number">3742.0</span><span class="token punctuation">,</span> <span class="token string">'PreSettlementPrice'</span><span class="token punctuation">:</span> <span class="token number">3734.2</span><span class="token punctuation">,</span> <span class="token string">'PreOpenInterest'</span><span class="token punctuation">:</span> <span class="token number">80947.0</span><span class="token punctuation">,</span> 
<span class="token string">'BidsJ'</span><span class="token punctuation">:</span> <span class="token number">3741.8</span><span class="token punctuation">,</span> <span class="token string">'BidsL'</span><span class="token punctuation">:</span> <span class="token number">3.0</span><span class="token punctuation">,</span> <span class="token string">'AsksJ'</span><span class="token punctuation">:</span> <span class="token number">3742.6</span><span class="token punctuation">,</span> <span class="token string">'AsksL'</span><span class="token punctuation">:</span> <span class="token number">1.0</span><span class="token punctuation">,</span> <span class="token string">'BidsL2'</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'AsksJ2'</span><span class="token punctuation">:</span> <span class="token number">6020.0</span><span class="token punctuation">,</span> <span class="token string">'AsksL2'</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span> 
<span class="token string">'BidsJ3'</span><span class="token punctuation">:</span> <span class="token number">5950.0</span><span class="token punctuation">,</span> <span class="token string">'BidsL3'</span><span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">'AsksJ3'</span><span class="token punctuation">:</span> <span class="token number">6025.0</span><span class="token punctuation">,</span> <span class="token string">'AsksL3'</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'BidsJ4'</span><span class="token punctuation">:</span> <span class="token number">5941.0</span><span class="token punctuation">,</span> <span class="token string">'BidsL4'</span><span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">'AsksJ4'</span><span class="token punctuation">:</span> <span class="token number">6028.0</span><span class="token punctuation">,</span> <span class="token string">'AsksL4'</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> 
<span class="token string">'BidsJ5'</span><span class="token punctuation">:</span> <span class="token number">5940.0</span><span class="token punctuation">,</span> <span class="token string">'BidsL5'</span><span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">'AsksJ5'</span><span class="token punctuation">:</span> <span class="token number">6030.0</span><span class="token punctuation">,</span> <span class="token string">'AsksL5'</span><span class="token punctuation">:</span> <span class="token number">5</span><span class="token punctuation">}</span>
</code></pre><hr>
<h5 id="18-前一周期时间">1.8、前一周期时间 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>shangcishijian  <span class="token comment"># 记录前一次k线时间，用于判断k线是否更新</span>
</code></pre><hr>
<h5 id="19-上次开仓编号">1.9、上次开仓编号 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>shangcikaicangbianhao  <span class="token comment"># 保存上次开仓编号，每次开仓openingdata中会有一个递增编号，这是保存的上次编号</span>
</code></pre><hr>
<h5 id="110-理论开平仓时间-数量-状态-价格和编号">1.10、理论开平仓时间、数量、状态、价格和编号 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>openingdata   <span class="token comment"># 理论开平仓时间、数量、状态、价格和编号</span>

<span class="token punctuation">{</span><span class="token string">'kaicangjia'</span><span class="token punctuation">:</span> <span class="token number">3000</span><span class="token punctuation">,</span> <span class="token string">'pingcangjia'</span><span class="token punctuation">:</span> <span class="token number">3000</span><span class="token punctuation">,</span> <span class="token string">'kaicangzhuangtai'</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'kaicangshuliang'</span><span class="token punctuation">:</span> <span class="token number">6</span><span class="token punctuation">,</span><span class="token string">'kaicangshijian'</span><span class="token punctuation">:</span> <span class="token number">2021</span><span class="token operator">-</span><span class="token number">11</span><span class="token operator">-</span><span class="token number">16</span> <span class="token number">14</span><span class="token punctuation">:</span><span class="token number">40</span><span class="token punctuation">:</span><span class="token number">30</span><span class="token punctuation">,</span>
<span class="token string">'pingcangshijian'</span><span class="token punctuation">:</span> <span class="token number">2021</span><span class="token operator">-</span><span class="token number">11</span><span class="token operator">-</span><span class="token number">18</span> <span class="token number">14</span><span class="token punctuation">:</span><span class="token number">40</span><span class="token punctuation">:</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">'name'</span><span class="token punctuation">:</span> openingdata<span class="token punctuation">[</span><span class="token string">'ruanjian2.0_taolixitong_v2_CFFEX.IF2309_30s'</span><span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token string">'bianhao'</span><span class="token punctuation">:</span> <span class="token number">18</span><span class="token punctuation">}</span>
</code></pre><p>开仓数量（kaicangshuliang）都为正，开仓转态（kaicangzhuangtai）持有多单时为1，持有空单时为-1</p>
<hr>
<h5 id="111-历史交易记录">1.11、历史交易记录 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>lishijiaoyijilu  <span class="token comment"># 如果初始化了历史信号，这里是保存历史交易记录，为df格式，有下单就会更新</span>
</code></pre><p>历史交易记录格式如下，fangxiang含义，1为开多，2为开空，3为平多，4为平空。<br>
注意：历史交易记录是一个字典。</p>
<table>
<thead>
<tr>
<th style="text-align:left">shijian</th>
<th style="text-align:left">fangxiang</th>
<th style="text-align:left">jiage</th>
<th style="text-align:left">shuliang</th>
<th style="text-align:left">fqxs</th>
<th style="text-align:left">heyue</th>
<th style="text-align:left">chengben</th>
<th style="text-align:left">yingkui</th>
<th style="text-align:left">leijiyingkui</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">20160630.133</td>
<td style="text-align:left">1</td>
<td style="text-align:left">5618</td>
<td style="text-align:left">8</td>
<td style="text-align:left">1</td>
<td style="text-align:left">v_zs</td>
<td style="text-align:left">40</td>
<td style="text-align:left">0</td>
<td style="text-align:left">0</td>
</tr>
<tr>
<td style="text-align:left">20161118.133</td>
<td style="text-align:left">3</td>
<td style="text-align:left">7189</td>
<td style="text-align:left">8</td>
<td style="text-align:left">1</td>
<td style="text-align:left">v_zs</td>
<td style="text-align:left">40</td>
<td style="text-align:left">62760</td>
<td style="text-align:left">62760</td>
</tr>
<tr>
<td style="text-align:left">20161221.11</td>
<td style="text-align:left">2</td>
<td style="text-align:left">6262</td>
<td style="text-align:left">6</td>
<td style="text-align:left">1</td>
<td style="text-align:left">v_zs</td>
<td style="text-align:left">30</td>
<td style="text-align:left">0</td>
<td style="text-align:left">62760</td>
</tr>
<tr>
<td style="text-align:left">20170110.14</td>
<td style="text-align:left">4</td>
<td style="text-align:left">6385</td>
<td style="text-align:left">6</td>
<td style="text-align:left">1</td>
<td style="text-align:left">v_zs</td>
<td style="text-align:left">30</td>
<td style="text-align:left">-3750</td>
<td style="text-align:left">59010</td>
</tr>
</tbody>
</table>
<hr>
<h5 id="112-持久化数据表">1.12、持久化数据表 </h5>
<p><em><strong>注意：其中cl.sjb["指定附图指标"]为保留字段，这个key专门用于指定需附图显示的指标，请用户不要占用。</strong></em><br>
<a href="%E5%AE%9E%E7%94%A8%E7%AD%96%E7%95%A5%E7%BC%96%E5%86%99%E6%8A%80%E5%B7%A7%E4%B8%8E%E6%A8%A1%E5%9D%97.html">主图附图显示设置方法详见《实用策略编写技巧与模块》</a></p>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>sjb   <span class="token comment"># 一个字典容器，用来存放需要长期保存的策略指标等数据，提供给用户长期保存指标用</span>

<span class="token comment"># cl.sjb["指定附图指标"] 为保留字段，这个key专门用于指定需附图显示的指标。</span>
cl<span class="token punctuation">.</span>sjb<span class="token punctuation">[</span><span class="token string">"指定附图指标"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">"zhibiao1"</span><span class="token punctuation">,</span><span class="token string">"zhibiao2"</span><span class="token punctuation">]</span>  <span class="token comment"># 指定指标1和指标2在附图显示</span>

<span class="token keyword keyword-return">return</span> a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">,</span> d  <span class="token comment"># 策略最后返回值依次为zhibiao1，zhibiao2，zhibiao3，zhibiao4.</span>
<span class="token comment"># 不用cl.sjb["指定附图指标"]字段将全部在主图显示指标，指标最多只能有4个。</span>

</code></pre><p><img src="../img/%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1/sjb%E5%80%BC%E8%AF%B4%E6%98%8E.png" alt="在这里插入图片描述"></p>
<hr>
<h5 id="113-输出指标序列每根k线保存也就是输出显示的四个指标">1.13、输出指标序列每根k线保存（也就是输出显示的四个指标） </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>shuchuzhibiao   <span class="token comment"># 没跟k线保存的数据，以字典方式加列表方式储存</span>
<span class="token punctuation">{</span><span class="token string">"riqishijian"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">"zhibiao1"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">"zhibiao2"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">"zhibiao3"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">"zhibiao4"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">}</span>

<span class="token comment"># 策略中可按需灵活使用</span>
</code></pre><hr>
<h5 id="114-乘值和最小变动单位">1.14、乘值和最小变动单位 </h5>
<p>说明：策略中可以直接通过下面属性获取第一个交易合约的乘值和最小变动，需要其他合约数据请用账户对象中获取最小变动和乘值的方法获取。</p>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>chengzhi <span class="token operator">=</span> <span class="token number">10</span>  <span class="token comment"># 第一个交易合约乘值</span>
cl<span class="token punctuation">.</span>zuixiaobiandong <span class="token operator">=</span> <span class="token number">1</span>  <span class="token comment"># 第一个交易合约最小变动</span>
</code></pre><hr>
<h5 id="115-上次开仓或平仓到当前k线数量距离">1.15、上次开仓或平仓到当前k线数量（距离） </h5>
<p><em><strong>说明：最开始从未开仓前，值一直累加，直到有开仓或平仓的当根为0，后面根据k线更新累加，这样一直往复。</strong></em></p>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>shoucikaicangjuli <span class="token operator">=</span> <span class="token number">0</span>  <span class="token comment"># 首次开仓到当前k线数量，开仓当根为0</span>
cl<span class="token punctuation">.</span>shoucipingcangjuli <span class="token operator">=</span> <span class="token number">0</span>  <span class="token comment"># 首次平仓到当前k线数量，平仓当根为0</span>

cl<span class="token punctuation">.</span>shangcikaicangjuli <span class="token operator">=</span> <span class="token number">0</span>  <span class="token comment"># 上次开仓到当前的k线数量，开仓当根为0</span>
cl<span class="token punctuation">.</span>shangcipingcangjuli <span class="token operator">=</span> <span class="token number">0</span> <span class="token comment"># 上次平仓到当前的k线数量，平仓当根为0</span>
</code></pre><p>用法之一是求开平仓后高低点，以便用于移动止盈止损，如下图：<br>
<img src="../img/%E7%AD%96%E7%95%A5%E5%AF%B9%E8%B1%A1/%E5%BC%80%E5%B9%B3%E4%BB%93%E5%90%8E%E6%9C%80%E9%AB%98.png" alt="在这里插入图片描述"></p>
<p>用法详见实用策略编写技巧与模块: <a href="%E5%AE%9E%E7%94%A8%E7%AD%96%E7%95%A5%E7%BC%96%E5%86%99%E6%8A%80%E5%B7%A7%E4%B8%8E%E6%A8%A1%E5%9D%97.html">实用策略编写技巧与模块</a></p>
<hr>
<h5 id="116-当前k线是否有交易信号">1.16、当前k线是否有交易信号 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code><span class="token comment"># 当前k线是否有交易信号，用于防止一根k线出现多次交易信号,只有非收盘运行时有效，设置为只收盘运行值永远为False</span>
cl<span class="token punctuation">.</span>dangqiankshifoujiaoyi <span class="token operator">=</span> <span class="token boolean">False</span>  <span class="token comment"># 默认为Fslse ,就是当前k线上没有交易信号</span>
<span class="token comment"># 示例，当当前k线没有交易信号才允许加仓，或平仓</span>
<span class="token keyword keyword-if">if</span> <span class="token keyword keyword-not">not</span> cl<span class="token punctuation">.</span>dangqiankshifoujiaoyi<span class="token punctuation">:</span>  <span class="token comment"># 防止当根k线又开又加仓又平仓</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
  <span class="token comment"># 加仓或平仓段代码</span>

</code></pre><h5 id="117-当前k线是否更新">1.17、当前k线是否更新 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code>cl<span class="token punctuation">.</span>bargengxin <span class="token operator">=</span> <span class="token boolean">False</span>  <span class="token comment"># k线更新的那一刻为true</span>
<span class="token comment"># 示例，当当前k线没有交易信号才允许加仓，或平仓</span>
<span class="token keyword keyword-if">if</span> cl<span class="token punctuation">.</span>bargengxin<span class="token punctuation">:</span>  <span class="token comment">#  更新k线时执行，一般用于收盘（k线更新）需要计算指标时</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
  <span class="token comment"># 指标等计算</span>

</code></pre><hr>
<h4 id="2-策略对象方法">2、策略对象方法 </h4>
<h5 id="21-获取n根k线前的日期">2.1、获取n根k线前的日期 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code><span class="token keyword keyword-def">def</span> <span class="token function">get_riqi</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> n<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span><span class="token builtin">int</span><span class="token punctuation">:</span>
    <span class="token triple-quoted-string string">"""
    获取n根k线前的日期
    :param n: n根bar前的日期，0为当前k线，1为上一根k线，以此类推
    :return: 需获取的日期,如20230715 为int
    """</span>
</code></pre><p>用法：日期 = cl.get_riqi()  # 获取当前k线的日期</p>
<hr>
<h5 id="21-获取n根k线前的时间">2.1、获取n根k线前的时间 </h5>
<pre data-role="codeBlock" data-info="python" class="language-python python"><code><span class="token keyword keyword-def">def</span> <span class="token function">get_shijian</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> n<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token builtin">float</span><span class="token punctuation">:</span>
    <span class="token triple-quoted-string string">"""
    获取n根k线前的时间
    :param n: n根bar前的时间，0为当前k线，1为上一根k线，以此类推
    :return: 需获取的时间,如0.2100 为float
    """</span>
</code></pre><p>用法：时间 = cl.get_shijian()  # 获取当前k线的时间</p>
<hr>

      </div>
      
      
    
    
    
    
    
    
  
    </body></html>